from flask import session, g
from models import UserModel


def login_before_request():
    account = session.get("account")
    if account:
        user = UserModel.query.filter_by(account=account).first()
        setattr(g, "user", user)
    else:
        setattr(g, "user", None)
